import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;

public class SolutionLCP56 {
    public int conveyorBelt(String[] matrix, int[] start, int[] end) {
        int[][] visit=new int[matrix.length][matrix[0].length()];
        for (int i=0;i<visit.length;i++){
            Arrays.fill(visit[i],Integer.MAX_VALUE);
        }
        visit[start[0]][start[1]]=0;
        Queue<int[]> queue=new LinkedList<>();
        queue.offer(start);
        int[] dx=new int[]{1,0,-1,0};
        int[] dy=new int[]{0,1,0,-1};
        char[] c=new char[]{'v','>','^','<'};
        while (!queue.isEmpty()){
            int[] t= queue.poll();
            for (int i=0;i<4;i++){
                int x=t[0]+dx[i];
                int y=t[1]+dy[i];
                if (x>=0 && x<matrix.length && y>=0 && y<matrix[0].length()){
                    int add=0;
                    if (matrix[t[0]].charAt(t[1])!=c[i]){
                        add++;
                    }
                    if (visit[x][y]>visit[t[0]][t[1]]+add){
                        visit[x][y]=visit[t[0]][t[1]]+add;
                        queue.offer(new int[]{x,y});
                    }
                }
            }
        }
        return visit[end[0]][end[1]];
    }

    public static void main(String[] args) {
        System.out.println(new SolutionLCP56().conveyorBelt(new String[]{">>v","v^<","<><"},new int[]{0,1},new int[]{2,0}));
    }
}
